
<style>
    #container{margin:0 auto; width:960px; padding-top: 300px;}
    #container .page_title{ text-align: center;}
    #container .form_content{width: 400px; margin: 0 auto;}
    #container .form_content .unit{margin: 10px; text-align: left;}
    #container .form_content .unit label{display: inline-block; width:80px; text-align:right; vertical-align: top;}
    #container .form_content .unit .input_submit{cursor: pointer;}

    #admin_login_captcha_img{width:100px; height:30px; border:1px solid #ccc; cursor:pointer;}
</style>

<span class="page_title"><h2>登录管理后台</h2></span>

<form id="admin_login_form" method="post" action="<?php echo $view_data['do_login_url']; ?>"  onsubmit="return do_login_action();">

    <div class="form_content">
        <div class="unit">
            <label>帐号：</label>
            <input type="text" id="user_name" name="user_name" value="" />
        </div>

        <div class="unit">
            <label>密码：</label>
            <input type="password" id="password" name="password" value="" />
        </div>
        <div class="unit">
            <label>验证码：</label>
            <input type="text" id="admin_login_captcha" name="admin_login_captcha" value="" />
            <label><img id="admin_login_captcha_img" src="<?php echo $view_data['login_captcha_url']; ?>" alt="换一张" title="换一张" onclick="refresh_captcha();" /></label>
        </div>

        <div class="unit">
            <label></label>
            <input class="input_submit" type="submit" value="提交" />
        </div>
    </div>

</form>

<script type="text/javascript">
    function refresh_captcha(){
        var login_captcha_url = "<?php echo $view_data['login_captcha_url']; ?>" + '&random/' + Math.random();
        $('#admin_login_captcha_img').attr('src', login_captcha_url);
    }

    function do_login_action(){
        $.ajax({
            type: 'POST',
            url: "<?php echo $view_data['do_login_url']; ?>",
            data: $('#admin_login_form').serialize(),
            dataType: 'json',
            success: function(rdata){
                if(rdata.status <= 0){
                    refresh_captcha();

                    alert(rdata.message);
                }else{
                    alert(rdata.message);

                    window.top.location.replace('<?php echo $view_data['good_index_url']; ?>');
                }

                return false;
            }
        });

        return false;
    }
</script>

